package com.acme.bankapp.domain.bank;

public class CheckingAccount extends AbstractAccount {

    private double overdraft;

    public CheckingAccount(final double amount, final double overdraft) {
        super(amount);
        this.overdraft = overdraft;
    }

    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
        }
    }

    public void withdraw(double amount) {
        if (balance >= amount) {
            balance -= amount;
        } else {
            double creditNeeded = amount - this.balance;
            if (overdraft >= creditNeeded) {
                balance = 0.0;
                overdraft -= creditNeeded;
            }
        }
    }

    public double maximumAmountToWithdraw() {
        return balance + overdraft;
    }
}
